package servlet;

import dao.Dao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/delAllShoppingCarGoodsServlet")
public class DelAllShoppingCarGoodsServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String suserid = request.getParameter("suserid");
        Dao dao = new Dao();
        int i = dao.delAllGoodFromCar(Integer.valueOf(suserid));
        if (i > 0) {
            response.sendRedirect(request.getContextPath() + "/ShoppingCarList.jsp?id=" + suserid);
        } else {
            request.setAttribute("updateGoodNumberInfo", "清空购物车失败，请重试");
            request.getRequestDispatcher("/ShoppingCarList.jsp?id=" + suserid).forward(request, response);
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
